﻿using BCCommon;
using BCCommon.TMS.Order;
using BCDto.TMS.Order.OrderCancelRecord;
using BCService.TMS.Order.OrderCancelRecord;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.Order
{
    /// <summary>
    /// 订单取消记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class OrderCancelRecordController : ManagementBaseController
    {
        private readonly IOrderCancelRecordService orderCancelRecordService;
        public OrderCancelRecordController(IOrderCancelRecordService orderCancelRecordService)
        {
            this.orderCancelRecordService = orderCancelRecordService;
        }

        #region 审核订单取消申请
        /// <summary>
        /// 审核订单取消申请
        /// </summary>
        /// <response code="200">审核订单取消申请</response>
        /// <returns></returns>
        [HttpPut("{order_cancel_record_id}")]
        [Log("审核订单取消申请")]
        [ProducesResponseType(typeof(OrderCancelRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "order_cancel_record_id")] int orderCancelRecordId, [FromBody] OrderCancelRecordPutDto putDto)
        {
            if (putDto.CancelStatus == OrderValidationStatus.Fail)
            {
                return Ok(this.orderCancelRecordService.ValidationFail(this.Admin, orderCancelRecordId, putDto));
            }
            return Ok(this.orderCancelRecordService.ValidationSuccess(this.Admin, orderCancelRecordId, putDto));
        }
        #endregion

        #region 获取订单取消记录——分页
        /// <summary>
        /// 获取订单取消记录——分页
        /// </summary>
        /// <response code="200">获取订单取消记录</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<OrderCancelRecordDto>), 200)]
        public IActionResult Get([FromQuery(Name = "driver_id")] long? driverId,
            [FromQuery(Name = "order_no")] string orderNo,
            [FromQuery(Name = "vehicle_no")] string vehicleNo,
            [FromQuery(Name = "driver_name")] string driverName,
            [FromQuery(Name = "cancel_status")] OrderValidationStatus? cancelStatus,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int pageIndex = 1,
            [FromQuery(Name = "size")] int pageSize = 10)
        {
            if (this.Admin.AgentRecord == null)
            {
                return Ok(this.orderCancelRecordService.Query(null, null, driverId, orderNo, vehicleNo, driverName, cancelStatus, start, end, ascending, pageIndex, pageSize));
            }

            return Ok(this.orderCancelRecordService.Query(null, this.Admin.AgentRecord.AgentRecordId, driverId, orderNo, vehicleNo, driverName, cancelStatus, start, end, ascending, pageIndex, pageSize));
        }
        #endregion

        #region 获取订单取消记录
        /// <summary>
        /// 获取订单取消记录
        /// </summary>
        /// <response code="200">获取订单取消记录</response>
        /// <returns></returns>
        [HttpGet("{order_cancel_record_id}")]
        [ProducesResponseType(typeof(OrderCancelRecordDto), 200)]
        public IActionResult Get([FromRoute(Name = "order_cancel_record_id")] int orderCancelRecordId)
        {
            return Ok(this.orderCancelRecordService.Get(orderCancelRecordId));
        }
        #endregion
    }
}
